package com.ytjj.qmyx.mall.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class WeekToDateUtil {

    //获取这一年的日历
    private static Calendar getCalendarFormYear(int year) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        cal.set(Calendar.YEAR, year);
        return cal;
    }


    //获取某一年的某一周的周日日期
    public static String getEndDayOfWeekNo(int year, int weekNo) {
        Calendar cal = getCalendarFormYear(year);
        cal.set(Calendar.WEEK_OF_YEAR, weekNo);
        cal.add(Calendar.DAY_OF_WEEK, 6);
        return (cal.get(Calendar.MONTH) + 1) + "/" +
                cal.get(Calendar.DAY_OF_MONTH);
    }

    //获取某一年的某一周的周一日期
    public static String getStartDayOfWeekNo(int year, int weekNo) {
        Calendar cal = getCalendarFormYear(year);
        cal.set(Calendar.WEEK_OF_YEAR, weekNo);

        return (cal.get(Calendar.MONTH) + 1) + "/" +
                cal.get(Calendar.DAY_OF_MONTH);
    }


    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        String startDayOfWeekNo = getStartDayOfWeekNo(2020, 85);
        String endDayOfWeekNo = getEndDayOfWeekNo(2020, 85);
        System.out.println(startDayOfWeekNo);
        System.out.println(endDayOfWeekNo);
    }
}
